package com.ocom.company.controller;

import com.alibaba.fastjson.JSON;
import com.ocom.common.constant.CompanyServiceUrl;
import com.ocom.common.entity.company.EntityDeviceUserBind;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.ResultUtil;
import com.ocom.company.service.DeviceUserBindService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
public class DeviceUserBindController {


    @Autowired
    private DeviceUserBindService deviceUserBindService;

    @GetMapping(CompanyServiceUrl.URL_mainAccountList)
    public Result mainAccountList(@RequestParam("comId") Long comId, @RequestParam("deviceId") String deviceId) {
        List<EntityDeviceUserBind> entityDeviceUserBinds = deviceUserBindService.mainAccountList(comId, deviceId);
        return ResultUtil.success(entityDeviceUserBinds);
    }

    @GetMapping(CompanyServiceUrl.URL_switchAccount)
    public Result switchAccount(@RequestParam("comId") Long comId, @RequestParam("userId") String userId, @RequestParam("deviceId") String deviceId) {
        String loginJson = deviceUserBindService.switchAccount(comId, userId, deviceId);
        Map map = JSON.parseObject(loginJson, Map.class);
        return ResultUtil.success(map);
    }

    @PostMapping(CompanyServiceUrl.URL_mainAccountBindDeviceUserBind)
    public Result mainAccountBindDeviceUserBind(@RequestParam("companyId") Long companyId, @RequestBody EntityDeviceUserBind entityDeviceUserBind) {
        deviceUserBindService.addBindDeviceUserBind(companyId, entityDeviceUserBind);
        return ResultUtil.success();
    }

}
